package com.wfh.wfhwx.config;

import com.wfh.wfhwx.handler.MessageHandler;
import jakarta.annotation.Resource;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Title: WxMpMsgRouterConfig
 * @Author wangfenghuan
 * @Package com.wfh.wfhwx.config
 * @Date 2025/6/21 10:12
 * @description: 微信消息路由配置
 */
@Configuration
public class WxMpMsgRouterConfig {

    private final WxMpService wxMpService = new WxMpServiceImpl();

    @Resource
    private MessageHandler messageHandler;

    /**
     * 配置消息路由规则
     * @return
     */
    @Bean
    public WxMpMessageRouter mpMessageRouter(){
        WxMpMessageRouter router = new WxMpMessageRouter(wxMpService);
        router.rule()
                .async(false)
                .msgType(WxConsts.XmlMsgType.TEXT)
                .handler(messageHandler)
                .end();
        return router;
    }
}
